<?php

namespace Admin\Controller;

use Think\Controller;
use Think\Exception;
use Think\Image;
use Think\Upload;

/*
create table `admin`
(
    id          int auto_increment primary key,
    account     char(20) unique  not null default '' comment '用户账号',
    password    varchar(255)     not null default '' comment '登陆密码',
    nickname    char(19)         not null default '默认昵称' comment '用户昵称',
    head_img    varchar(255)     not null default '' comment '用户头像',
    role_id     tinyint unsigned not null default 0 comment '用户角色ID',
    status      enum ('0','1')   not null default '1' comment '状态',
    create_time datetime comment '创建时间',
    update_time timestamp comment '修改时间'
) engine innodb comment '后台管理员表';
 * */

class AdminController extends Controller
{
    protected $arr = array('code' => 0, 'msg' => '预定义返回错误', 'data' => array('name'=>'xiongzhu'));
    protected $model = null;
    protected $error = 0; //错误次数

    public function _initialize()
    {
        $this->model = 'admin';
    }

    public function index()
    {

        dump($this->error);
    }

    public function login()
    {
        try {
//            $error = session('error');
////            if ($error >= 5) throw new Exception('错误次数达到五次,不能再登陆咯, 亲');
//            $password = I('post.password');
//            $account = I('post.account');
//            $data = array(); //假装是从数据库取出来的
//            if (!password_verify($password, $data['password'])) {
//                $error = $error + 1;
//                session('error', $error);
////                throw new Exception('第' . $error . '次密码错误,五次错误将不能登陆');
//            }
        } catch (Exception $e) {
            $this->arr['msg'] = $e->getMessage();
        }
        $this->ajaxReturn($this->arr);

    }
}